/**
 * 
 */
package metalink.admin;

import java.util.ArrayList;
import java.util.Map;
import java.util.Vector;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import model.admin.GetStaffListMo;
import model.admin.StaffFinancialsMo;

import vo.CollegeStaffVo;
import vo.StaffFinancialsVo;
import vo.mixed.CollegeStaffFinancialsVo;
import vo.mixed.HostelStudentVo;

import com.opensymphony.xwork2.ActionSupport;

/**
 * @author Sony
 * 
 */
public class GetFinancials extends ActionSupport {
	ArrayList<CollegeStaffVo> list = new ArrayList<CollegeStaffVo>();
	ArrayList<CollegeStaffFinancialsVo> financelist = new ArrayList<CollegeStaffFinancialsVo>();
	String type = "",edit="";
	int salary_amount;
	String salary_date;
	int payment_made;
	int year;
	int month;
	int acc_no;
	String roll_number;
	String transaction_id;
	int staff_id;
	int college_staff_financial_id;
	HttpSession session;
	private int result;
	//------------ Pagination --------------//
		private int page;
	    private String morepages;
		private Vector noofpages=new Vector();
		private int nextpage;
		private int currentpage;
		private String hasprevpage;
		private int prevpage;
		private int items;
		//private Vector pagelist=new Vector();
		private ArrayList<CollegeStaffVo> pagelist;
		String ret;

	public String execute() {
		pagelist = new ArrayList<CollegeStaffVo>();
		// CollegeStaffFinancialsVo vo=new CollegeStaffFinancialsVo();
		System.out.println("edit="+edit+" id="+staff_id);
		session = ServletActionContext.getRequest().getSession();
		session.setAttribute("staf_id", staff_id);
		if (type.equals("staff")) {
			System.out.println("in if : edit="+edit+" id="+staff_id);
			if(edit.equals(""))
			{
			GetStaffListMo mo = new GetStaffListMo();
			list = mo.getStaffList();
			
			result = list.size();
			
			//---------- Pagination ------------------//
			
			int p=getPage();
		    if(p==0)
		    {
		        setHasprevpage("false");
		    }
		    else
		    {
		        setHasprevpage("true");
		        setPrevpage(p-1);
		    }

		    setCurrentpage(p);

		    int count;
		    count=0;

		    int size=list.size();
		    setItems(size);
		    int pagesinlist=size/15;
		    while(count<=pagesinlist)
		    {
		        noofpages.add(count);
		        count++;
		    }
		    count=0;
		    while(count<15)
		    {

		        if(size>=(p*15)+count+1)
		        {
		            System.out.println(p);
		            pagelist.add(list.get((p*15)+count));
		            System.out.println((p*15)+count);
		            System.out.println("size"+pagelist.size());
		            count++;
		            setMorepages("true");
		            setNextpage(p+1);

		        }
		        else
		        {
		            setMorepages("false");
		            break;
		        }
		    }
			
			
			return SUCCESS;
			}
			else if(edit.equals("addnewentry"))
			{
				System.out.println("add new entry...!!");
				GetStaffListMo mo = new GetStaffListMo();
				list=mo.getStaffDetails(staff_id);
				ret = "addnewentry";
			}
			else if(edit.equals("editentry"))
			{
				System.out.println("edit entry...!!");
				StaffFinancialsMo mo=new StaffFinancialsMo();
				financelist=mo.getEntryDetails(college_staff_financial_id);
				ret = "editentry";
			}
			else if(edit.equals("editedentry"))
			{
				StaffFinancialsVo vo=new StaffFinancialsVo();
				vo.setMonth(month);
				vo.setPayment_made(payment_made);
				vo.setSalary_amount(salary_amount);
				vo.setStaff_id(staff_id);
				vo.setTransaction_id(transaction_id);
				vo.setYear(year);
				vo.setCollege_staff_financial_id(college_staff_financial_id);
				vo.setAcc_no(acc_no);
				StaffFinancialsMo mo=new StaffFinancialsMo();
				mo.editEntry(vo, edit);
				ret = "editedentry";
			}
			else if(edit.equals("viewall"))
			{
				System.out.println("view all...!!");
				StaffFinancialsMo mo=new StaffFinancialsMo();
				financelist=mo.getFinancialHistory(staff_id);
				ret = "viewall";
			}
			else if(edit.equals("delentry"))
			{
				StaffFinancialsMo mo=new StaffFinancialsMo();
				mo.deleteEntry(college_staff_financial_id);
				ret = "edited";
			}
			else if(edit.equals("add"))
			{
				StaffFinancialsVo vo=new StaffFinancialsVo();
				vo.setMonth(month);
				vo.setPayment_made(payment_made);
				vo.setSalary_amount(salary_amount);
				vo.setStaff_id(staff_id);
				vo.setTransaction_id(transaction_id);
				vo.setYear(year);
				vo.setAcc_no(acc_no);
				StaffFinancialsMo mo=new StaffFinancialsMo();
				mo.addEntry(vo,edit);
				ret = "added";
			}
		}
		result = list.size();
		
		//---------- Pagination ------------------//
		
		int p=getPage();
	    if(p==0)
	    {
	        setHasprevpage("false");
	    }
	    else
	    {
	        setHasprevpage("true");
	        setPrevpage(p-1);
	    }

	    setCurrentpage(p);

	    int count;
	    count=0;

	    int size=list.size();
	    setItems(size);
	    int pagesinlist=size/15;
	    while(count<=pagesinlist)
	    {
	        noofpages.add(count);
	        count++;
	    }
	    count=0;
	    while(count<15)
	    {

	        if(size>=(p*15)+count+1)
	        {
	            System.out.println(p);
	            pagelist.add(list.get((p*15)+count));
	            System.out.println((p*15)+count);
	            System.out.println("size"+pagelist.size());
	            count++;
	            setMorepages("true");
	            setNextpage(p+1);

	        }
	        else
	        {
	            setMorepages("false");
	            break;
	        }
	    }
		return ret;
	}

	public int getCollege_staff_financial_id() {
		return college_staff_financial_id;
	}

	public void setCollege_staff_financial_id(int college_staff_financial_id) {
		this.college_staff_financial_id = college_staff_financial_id;
	}

	public int getStaff_id() {
		return staff_id;
	}

	public void setStaff_id(int staff_id) {
		this.staff_id = staff_id;
	}

	public String getEdit() {
		return edit;
	}

	public void setEdit(String edit) {
		this.edit = edit;
	}

	public ArrayList<CollegeStaffVo> getList() {
		return list;
	}

	public void setList(ArrayList<CollegeStaffVo> list) {
		this.list = list;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public ArrayList<CollegeStaffFinancialsVo> getFinancelist() {
		return financelist;
	}

	public void setFinancelist(ArrayList<CollegeStaffFinancialsVo> financelist) {
		this.financelist = financelist;
	}

	public int getSalary_amount() {
		return salary_amount;
	}

	public void setSalary_amount(int salary_amount) {
		this.salary_amount = salary_amount;
	}

	public String getSalary_date() {
		return salary_date;
	}

	public void setSalary_date(String salary_date) {
		this.salary_date = salary_date;
	}

	public int getPayment_made() {
		return payment_made;
	}

	public void setPayment_made(int payment_made) {
		this.payment_made = payment_made;
	}

	public int getYear() {
		return year;
	}

	public void setYear(int year) {
		this.year = year;
	}

	public int getMonth() {
		return month;
	}

	public void setMonth(int month) {
		this.month = month;
	}

	public int getAcc_no() {
		return acc_no;
	}

	public void setAcc_no(int acc_no) {
		this.acc_no = acc_no;
	}

	public String getRoll_number() {
		return roll_number;
	}

	public void setRoll_number(String roll_number) {
		this.roll_number = roll_number;
	}

	public String getTransaction_id() {
		return transaction_id;
	}

	public void setTransaction_id(String transaction_id) {
		this.transaction_id = transaction_id;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public String getMorepages() {
		return morepages;
	}

	public void setMorepages(String morepages) {
		this.morepages = morepages;
	}

	public Vector getNoofpages() {
		return noofpages;
	}

	public void setNoofpages(Vector noofpages) {
		this.noofpages = noofpages;
	}

	public int getNextpage() {
		return nextpage;
	}

	public void setNextpage(int nextpage) {
		this.nextpage = nextpage;
	}

	public int getCurrentpage() {
		return currentpage;
	}

	public void setCurrentpage(int currentpage) {
		this.currentpage = currentpage;
	}

	public String getHasprevpage() {
		return hasprevpage;
	}

	public void setHasprevpage(String hasprevpage) {
		this.hasprevpage = hasprevpage;
	}

	public int getPrevpage() {
		return prevpage;
	}

	public void setPrevpage(int prevpage) {
		this.prevpage = prevpage;
	}

	public int getItems() {
		return items;
	}

	public void setItems(int items) {
		this.items = items;
	}

	public ArrayList<CollegeStaffVo> getPagelist() {
		return pagelist;
	}

	public void setPagelist(ArrayList<CollegeStaffVo> pagelist) {
		this.pagelist = pagelist;
	}

	public int getResult() {
		return result;
	}

	public void setResult(int result) {
		this.result = result;
	}

	public String getRet() {
		return ret;
	}

	public void setRet(String ret) {
		this.ret = ret;
	}
}
